package com.student.utils;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class trigger {
    public static void createTriggers() {
        String insertTriggerSQL = "DELIMITER $$\n" +
                "CREATE TRIGGER update_class_num_on_insert\n" +
                "AFTER INSERT ON s_student\n" +
                "FOR EACH ROW\n" +
                "BEGIN\n" +
                "   UPDATE s_class\n" +
                "   SET num = num + 1\n" +
                "   WHERE classname = NEW.class;\n" +
                "END$$\n" +
                "DELIMITER ;";
        DBMysql.update(insertTriggerSQL);
    }
//注意只有添加的触发器能运行，删除和修改要在数据库里创建触发器
    public static void main(String[] args) {
    }
}
